package com.physics.mps.module.setting;

import com.physics.mps.entity.dto.AppParamGroupEntity;
import com.physics.mps.entity.vo.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author mcsoft
 * @date 2023/09/15 16:22
 **/
@Api(tags = "appParamGroup接口")
@RestController
@RequestMapping(value = "/appParamGroup")
@RequiredArgsConstructor
public class AppParamGroupController {

    private final AppParamGroupEntityService appParamGroupService;

    @ApiOperation(value = "新增分组")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "authorization", value = "authorization", dataType = "String", required = true)
    })
    @PostMapping("/addGroup")
    public ResponseResult addGroup(@Validated @RequestBody AppParamGroupEntity appParamGroupEntity) {
        return ResponseResult.success(appParamGroupService.save(appParamGroupEntity));
    }

    @ApiOperation(value = "编辑分组")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "authorization", value = "authorization", dataType = "String", required = true)
    })
    @PostMapping("/editGroup")
    public ResponseResult editGroup(@Validated @RequestBody AppParamGroupEntity appParamGroupEntity) {
        return ResponseResult.success(appParamGroupService.updateById(appParamGroupEntity));
    }

    @ApiOperation(value = "删除分组")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "authorization", value = "authorization", dataType = "String", required = true)
    })
    @PostMapping("/deleteGroup/{id}")
    public ResponseResult deleteGroup(@PathVariable("id") String id) {
        return ResponseResult.success(appParamGroupService.removeById(id));
    }
}
